<template>
  <div class="bg">
    <router-view></router-view>
    <div class="exo">
      <div class="choosetag">
        <div class="left">
          <span>{{curcat}}</span>
          <a
            href="#"
            @click.prevent="changeCart"
          >选择分类</a>
        </div>
        <div class="right">
          <a href="#">热门</a>
        </div>
      </div>
      <!-- 分类列表 -->
      <div
        class="alltag"
        v-show="showDropdown"
      >
        <p class="tit">全部风格</p>
        <dl class="f-dl">
          <dt>
            <i class="iconfont icon-wanggediqiu"></i>
            <span>语种</span>
          </dt>
          <dd>
            <div
              class="he"
              v-for="(item,index) in taglist0"
              :key="index"
            ><a
                href="#"
                @click.prevent="cagCart(item.name)"
              >{{item.name}}</a>
              <span>|</span></div>
          </dd>
        </dl>
        <dl class="f-dl">
          <dt>
            <i class="iconfont icon-gangqin"></i>
            <span>风格</span>
          </dt>
          <dd>
            <div
              class="he"
              v-for="(item,index) in taglist1"
              :key="index"
            >
              <a href="#">{{item.name}}</a>
              <span>|</span>
            </div>

          </dd>
        </dl>
        <dl class="f-dl">
          <dt>
            <i class="iconfont icon-cha"></i>
            <span>场景</span>
          </dt>
          <dd>
            <div
              class="he"
              v-for="(item,index) in taglist2"
              :key="index"
            >
              <a href="#">{{item.name}}</a>
              <span>|</span>
            </div>

          </dd>
        </dl>
        <dl class="f-dl">
          <dt>
            <i class="iconfont icon-xiaolian1"></i>
            <span>情感</span>
          </dt>
          <dd>
            <div
              class="he"
              v-for="(item,index) in taglist3"
              :key="index"
            >
              <a href="#">{{item.name}}</a>
              <span>|</span>
            </div>

          </dd>
        </dl>
        <dl class="f-dl">
          <dt>
            <i class="iconfont icon-gangqin"></i>
            <span>主题</span>
          </dt>
          <dd>
            <div
              class="he"
              v-for="(item,index) in taglist4"
              :key="index"
            >
              <a href="#">{{item.name}}</a>
              <span>|</span>
            </div>

          </dd>
        </dl>
      </div>
      <!-- 歌单显示块 -->
      <ul class="m-cvrlst">
        <li
          v-for="(item,index) in songlist"
          :key="index"
          @click="hotjiandetail(item.id)"
        >
          <div class="cover">
            <img
              v-lazy="item.coverImgUrl"
              @click.prevent="goAlbum(item.id)"
            >
            <i class="iconfont"></i>
            <div class="btm">
              <a
                href="#"
                class="iconfont icon-bofang"
              ></a>
              <span class="iconfont icon-erjiyuyin"></span>
              <span class="nb">{{item.playCount}}万</span>
            </div>
          </div>
          <p class="name">
            <a
              href="#"
              class="f-thide"
              @click.prevent="goAlbum(item.id)"
            >{{item.name}}</a>
          </p>
          <p class="aut">
            <span>by</span>
            <a
              href="#"
              class="f-thide"
            >{{item.creator.nickname}}</a>
            <img src="../../../assets/image/logoq.png">
          </p>
        </li>
      </ul>
      <!-- 分页 -->
      <el-pagination
        background
        layout="prev, pager, next"
        :page-size="35"
        :total="1200"
        :current-page="nowpage"
        prev-text="< 上一页"
        next-text="下一页 >"
        @current-change="changepage"
      >
      </el-pagination>
    </div>

  </div>
</template>

<script>
import axios from 'axios'
import { constants } from 'os';
export default {
  data () {
    return {
      plistID: 0,
      // 所有标签
      taglist: [],
      taglist0: [],
      taglist1: [],
      taglist2: [],
      taglist3: [],
      taglist4: [],
      songlist: [{
        playCount: 0,
        creator: {
          nickname: ''
        }
      }],
      // 当前页数
      nowpage: 1,
      showDropdown: false,
      curcat: '全部',
      // showPlayList: true
    }
  },
  created () {
    this.getTagList()
    this.getsongList()
  },
  mounted () {
    this.getTagList()
    this.getsongList()
  },
  // watch: {
  //   plistID (newVal, oldVal) {
  //     console.log(newVal, oldVal)
  //   }
  // },
  methods: {
    // 获取标签列表
    async getTagList () {
      // console.log('进入了playlist')
      let res = await axios.get('https://autumnfish.cn//playlist/highquality/tags')
      // console.log(res)
      this.taglist = res.data.tags
      this.taglist0 = this.taglist.filter((item, index) => {
        return item.category === 0;
      })
      this.taglist1 = this.taglist.filter((item, index) => {
        return item.category === 1;
      })
      this.taglist2 = this.taglist.filter((item, index) => {
        return item.category === 2;
      })
      this.taglist3 = this.taglist.filter((item, index) => {
        return item.category === 3;
      })
      this.taglist4 = this.taglist.filter((item, index) => {
        return item.category === 4;
      })
    },
    // 获取歌单（分页用的数据）
    async getsongList () {
      let offst = (this.nowpage - 1) * 35
      let res = await axios.get('https://autumnfish.cn//top/playlist?cat=' + this.curcat + '&limit=35&order=hot&offset=' + offst);
      // console.log(res)
      this.songlist = res.data.playlists
      this.songlist.playCount = Math.round(this.songlist.playCount / 10000)
    },
    // 改变页数
    changepage (val) {
      this.nowpage = val;
      // console.log(this.nowpage)
      this.getsongList()
    },
    // 显示隐藏分类选项卡
    changeCart () {
      // 1、显示选择框
      this.showDropdown = !this.showDropdown
      // document.getElementsByClassName('alltag')[0].style.display = 'block'

    },
    // 点击某个分类触发
    cagCart (cat) {
      // 1、隐藏选项框
      this.changeCart()
      // 2、重新请求对应数据
      this.curcat = cat;
      this.getsongList()
    },
    hotjiandetail (id) {
      // 2、跳转
      this.plistID = id;
      this.$router.push({ name: 'pldetail', params: { id: this.plistID } })
      // this.$router.push({ path: '/discover/playlist', query: { id: this.plistID } })
    },
    goAlbum (id) {
      this.$router.push({ path: '/playlist', query: { id: id } })
      // 上面的更改了地址，但数据未更新。因为是自己眺自己
      // 下面是为了刷新数据————————————————————————待优化
      this.getTagList()
      this.getsongList()
      // this.$router.go(0);      

    }
  }
}
</script>

<style lang="less" scoped>
a {
  text-decoration: none;
}
.bg {
  width: 980px;
  min-height: 700px;
  margin: 0 auto;
  background-color: #fff;
  border: 1px solid #d3d3d3;
  border-width: 0 1px;
  padding: 40px;
  position: relative;
  .choosetag {
    height: 40px;
    border-bottom: 2px solid #c20c0c;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .left {
      display: flex;
      justify-content: left;
      align-items: center;
      span {
        font-size: 24px;
      }
      a {
        display: inline-block;
        border-radius: 4px;
        width: 85px;
        height: 30px;
        line-height: 30px;
        text-align: center;
        font-size: 12px;
        margin: 2px 0 0 12px;
        color: #0c73c2;
        background-color: #f2f2f2;
        border: 1px solid #333;
      }
    }
    .right {
      height: 29px;
      border-radius: 3px;
      a {
        display: inline-block;
        border-radius: 3px;
        width: 46px;
        height: 29px;
        line-height: 29px;
        text-align: center;
        color: #fff;
        background-color: #be0a0d;
      }
    }
  }
  .alltag {
    position: absolute;
    left: 10px;
    top: 90px;
    width: 700px;
    padding: 20px 10px;
    border: 1px solid #000;
    z-index: 2147483647;
    background-color: #fff;
    // display: none;
    .tit {
      border-radius: 4px;
      padding: 0;
      margin: 0;
      width: 75px;
      height: 26px;
      background-color: #f4f4f4;
      text-align: center;
      line-height: 26px;
      font-size: 12px;
      margin-bottom: 10px;
    }
    .f-dl {
      padding: 0;
      margin: 0;
      font-size: 12px;
      margin: 20px 0;
      dt {
        float: left;
        display: inline;
        width: 70px;
        margin: 0 -100px 0 26px;
        padding-top: 15px;
        border-right: 1px solid #e6e6e6;
        font-weight: bold;
        .iconfont {
          font-size: 20px;
          margin-right: 8px;
          color: #afacac;
          font-weight: normal;
        }
      }
      dd {
        margin-left: 96px;
        padding: 16px 15px 0 15px;
        border-left: 1px solid #e6e6e6;
        line-height: 24px;
        .he {
          display: inline;
          a {
            color: #333;
          }
          a:hover {
            text-decoration: underline;
            color: #000;
          }
          span {
            margin: 0 10px 0 10px;
            color: #666;
          }
        }
      }
    }
  }
  .m-cvrlst {
    margin: 0;
    padding: 0;
    margin: 30px 0 0 -50px;
    display: flex;
    justify-content: left;
    align-items: center;
    flex-wrap: wrap;
    li {
      list-style: none;
      width: 140px;
      height: 188px;
      overflow: hidden;
      padding: 0 0 30px 50px;
      line-height: 1.4;
      .cover {
        width: 140px;
        height: 140px;
        position: relative;
        img {
          display: block;
          width: 100%;
          height: 100%;
        }
        i {
          position: absolute;
          top: 0;
          left: 0;
          width: 40px;
          height: 40px;
          background-image: url(../../../assets/image/icon2.png);
          background-position: -135px -220px;
        }
        .btm {
          position: absolute;
          bottom: 0;
          left: 0;
          width: 100%;
          height: 27px;
          background-color: rgba(0, 0, 0, 0.5);
          color: #ccc;
          a {
            text-decoration: none;
            position: absolute;
            right: 10px;
            bottom: 5px;
            width: 16px;
            height: 17px;
            font-size: 16px;
            color: #e7e7e7;
          }
          .icon-erjiyuyin {
            float: left;
            font-size: 16px;
            margin: 5px 5px 0 10px;
          }
          .nb {
            float: left;
            margin: 7px 0 0 0;
            font-size: 12px;
          }
        }
      }
      p {
        margin: 0;
        padding: 0;
      }
      .name {
        margin: 8px 0 3px;
        font-size: 14px;
        a {
          color: #333;
          text-decoration: none;
          display: inline-block;
          max-width: 100%;
          vertical-align: middle;
        }
        a:hover {
          text-decoration: underline;
        }
      }
      .aut {
        span {
          color: #999;
        }
        a {
          color: #999;
          max-width: 76%;
          display: inline-block;
          vertical-align: middle;
          font-size: 12px;
          margin: 0 5px;
        }
        a:hover {
          text-decoration: underline;
        }
        img {
          height: 13px;
          width: 13px;
          display: inline-block;
          vertical-align: middle;
        }
      }
    }
  }
}
</style>
